package com.miao.activity.run;

import com.miao.activity.entity.MiaoActivityEntity;
import com.miao.activity.entity.OrderInfoEntity;
import com.miao.activity.filter.UserFilter;
import com.miao.activity.service.MiaoActivityService;
import com.miao.activity.service.OrderInfoService;
import com.miao.commonn.utils.R;
import com.miao.commonn.vo.GoodsVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.data.redis.core.BoundHashOperations;
import org.springframework.data.redis.core.HashOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author 武者
 * @title: StartRun
 * @projectName miaosha
 * @description:
 * @date 2022/3/3 21:41
 */
@Component
public class StartRun implements ApplicationRunner {

    @Autowired
    private UserFilter userFilter;

    @Autowired
    private OrderInfoService orderInfoService;

    @Autowired
    MiaoActivityService miaoActivityService;

    @Autowired
    RedisTemplate redisTemplate;

    @Override
    public void run(ApplicationArguments args) throws Exception {


        List<GoodsVo> lists = userFilter.lists();

        BoundHashOperations goods = redisTemplate.boundHashOps("goods_list");

        for (GoodsVo list : lists) {
            goods.put(list.getGoodsId(),list);
        }

        List<OrderInfoEntity> list = orderInfoService.list();


        BoundHashOperations order_list = redisTemplate.boundHashOps("order_list");
        for (OrderInfoEntity orderInfoEntity : list) {

            order_list.put(orderInfoEntity.getOid(),orderInfoEntity);
        }

        List<MiaoActivityEntity> list1 = miaoActivityService.list();
        BoundHashOperations activity_list = redisTemplate.boundHashOps("activity_list");
        for (MiaoActivityEntity miaoActivityEntity : list1) {

            activity_list.put(miaoActivityEntity.getMiaoId(),miaoActivityEntity);


        }


    }
}
